var SPSdk = (function () {
    var URL = "http://h5.91wan.com/api/dataapi.php";
    var SDK = "http://h5.91wan.com/js/7wanwansdk.js";


    function SPSdk() {
        this.spId = 0;
        this.appId = "";
        this.appKey = "";
        this.token = "";
        this.spFname = "";
        this.openKey = "";
    }

    var __proto = SPSdk.prototype;

    __proto.login = function (param, callback, shareHandler) {
        console.log("91WAN登录：" + JSON.stringify(param));
        var m_this = this;
        if (param.ret == 0) {
            quwanwansdk.getLoginInfo({
                "game_id": m_this.appId,
                "server_id": 0,
                "callFunc": function (response) {
                    callback && callback({
                        "result": 0,
                        "spuid": response.uid,
                        "img":response.img,
                        "nickname": response.nick_name,
                        "access_token":response.access_token
                    });
                }
            });
        }
    };

    //__proto.share = function (param, callback) {
    //    quwanwansdk.change_share_info({
    //        title:param.title,
    //        summary:param.desc,
    //        img_url:param.imgsrc,
    //        callFunc: function (status) {
    //            var data;
    //            if (status == "success") {
    //                data = {result:0,desc:"分享成功"};
    //            }else{
    //                data = {result:-4,desc:"分享成功"};
    //            }
    //            callback&&callback(data)
    //        },
    //        show_share: true
    //    });
    //
    //};
    __proto.pay = function (param, callback) {
        var m_this = this;
        console.log("91WAN支付：" + JSON.stringify(param));
        if (param.ret == 0) {
            if(!param.data.other.token || !param.data.other.sign)
            {
                callback&&callback({result:-1,desc:"请求订单失败"});
                return;
            }
            quwanwansdk.pay({
                token: param.data.other.token,
                sign: param.data.other.sign,
                callFunc: function (status,msg) {
                    if (status == "success") {
                        callback&&callback({result:0,desc:"成功"});
                    }else{
                        callback&&callback({result:-1,desc:msg});
                    }
                }
            });
        }
    };

    __proto.init = function (param, callback) {
        console.log("91WAN初始化：" + JSON.stringify(param));
        var m_this = this;
        LayaCommon.loadScript(SDK, function () {
            m_this.access_token = param.access_token;
            m_this.spId = param.spId;
            m_this.appId = param.appId;
            m_this.spFname = param.spFname;
            m_this.openKey = param.openKey;
            callback && callback({"result": 0, "desc": "OK", "sp_data": null});
        });
    };
    return SPSdk;
})();